<template>
  <div  style="background-color: white;height: 100%; width: 100%; padding-top: 20px">
    <div style="float: left; padding-left: 10px">
      <span>品号：</span>
      <el-select v-model="valurArr" multiple placeholder="请选择品号">
        <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
        </el-option>
      </el-select>
      <el-button @click="getRecord" type="primary" style="margin-left: 30px">查询</el-button>
      <el-button @click="submit" type="primary" style="margin-left: 30px" v-loading.fullscreen.lock="fullscreenLoading">
        提交
      </el-button>


      <!--      <el-button @click="print" type="primary" style="margin-left: 30px" v-loading.fullscreen.lock="fullscreenLoading">打印</el-button>-->
    </div>
    <div style="padding-top: 30px; height: 30px"></div>
    <el-form style="width: 100%" :inline="true" label-position="right" :model="formInline" label-width="80px">

      <template style="width: 100%" v-for="(item,index) in tableData">
        <el-tag style="float: left; margin-bottom: 5px; padding-left: 10px">品号:{{ item[0].productNo }}</el-tag>
        <el-table
            :data="item"
            border
        >
          <el-table-column
              label="品名"
              prop="productName"
              align="center"
              width="180">
            <template slot-scope="scope">
              <div v-if="scope.$index == 1">
                <el-form-item>
                  <el-input v-model="formInline[index].productName" size="mini" placeholder="点击输入品名"/>
                </el-form-item>
              </div>
              <div v-else>{{ (scope.row.productName) }}</div>
            </template>
          </el-table-column>
          <el-table-column
              prop="specification"
              label="规格"
              align="center"
              width="180">
            <template slot-scope="scope">
              <div v-if="scope.$index == 1">
                <el-form-item>
                  <el-input v-model="formInline[index].specification" size="small" placeholder="点击输入规格"/>
                </el-form-item>
              </div>
              <div v-else>{{ (scope.row.specification) }}</div>
            </template>
          </el-table-column>
          <el-table-column
              prop="texture"
              label="材质"
              align="center"
              width="180">
            <template slot-scope="scope">
              <div v-if="scope.$index == 1">
                <el-form-item>
                  <el-input v-model="formInline[index].texture" size="small" placeholder="点击输入材质"/>
                </el-form-item>
              </div>
              <div v-else>{{ (scope.row.texture) }}</div>
            </template>
          </el-table-column>
          <el-table-column
              prop="thickness"
              label="直径/厚度"
              align="center"
              width="180">
            <template slot-scope="scope">
              <div v-if="scope.$index == 1">
                <el-form-item>
                  <el-input v-model="formInline[index].thickness" size="small" placeholder="点击输入厚度"/>
                </el-form-item>
              </div>
              <div v-else>{{ (scope.row.thickness) }}</div>
            </template>
          </el-table-column>
          <el-table-column
              prop="width"
              label="宽度"
              align="center"
              width="180">
            <template slot-scope="scope">
              <div v-if="scope.$index == 1">
                <el-form-item>
                  <el-input v-model="formInline[index].width" size="small" placeholder="点击输入宽度"/>
                </el-form-item>
              </div>
              <div v-else>{{ (scope.row.width) }}</div>
            </template>
          </el-table-column>
          <el-table-column
              prop="extent"
              label="长度"
              align="center"
              width="180">
            <template slot-scope="scope">
              <div v-if="scope.$index == 1">
                <el-form-item>
                  <el-input v-model="formInline[index].extent" size="small" placeholder="点击输入长度"/>
                </el-form-item>
              </div>
              <div v-else>{{ (scope.row.extent) }}</div>
            </template>
          </el-table-column>
          <el-table-column
              prop="steelNo"
              label="牌号钢号"
              align="center"
              width="180">
            <template slot-scope="scope">
              <div v-if="scope.$index == 1">
                <el-form-item>
                  <el-input v-model="formInline[index].steelNo" size="small" placeholder="点击输入牌号钢号"/>
                </el-form-item>
              </div>
              <div v-else>{{ (scope.row.steelNo) }}</div>
            </template>
          </el-table-column>
          <el-table-column
              prop="hardness"
              label="抗拉/硬度"
              align="center"
              width="180">
            <template slot-scope="scope">
              <div v-if="scope.$index == 1">
                <el-form-item>
                  <el-input v-model="formInline[index].hardness" size="small" placeholder="点击输入抗拉"/>
                </el-form-item>
              </div>
              <div v-else>{{ (scope.row.hardness) }}</div>
            </template>
          </el-table-column>
          <el-table-column
              prop="placeOfOrigin"
              label="产地"
              align="center"
              width="180">
            <template slot-scope="scope">
              <div v-if="scope.$index == 1">
                <el-form-item>
                  <el-input v-model="formInline[index].placeOfOrigin" size="small" placeholder="点击输入产地"/>
                </el-form-item>
              </div>
              <div v-else>{{ (scope.row.placeOfOrigin) }}</div>
            </template>
          </el-table-column>
          <el-table-column
              prop="brand"
              label="牌子"
              align="center"
              width="180">
            <template slot-scope="scope">
              <div v-if="scope.$index == 1">
                <el-form-item>
                  <el-input v-model="formInline[index].brand" size="small" placeholder="点击输入牌子"/>
                </el-form-item>
              </div>
              <div v-else>{{ (scope.row.brand) }}</div>
            </template>
          </el-table-column>
          <el-table-column
              prop="executiveStandard"
              label="执行标准"
              align="center"
              width="180">
            <template slot-scope="scope">
              <div v-if="scope.$index == 1">
                <el-form-item>
                  <el-input v-model="formInline[index].executiveStandard" size="small" placeholder="点击输入执行标准"/>
                </el-form-item>
              </div>
              <div v-else>{{ (scope.row.executiveStandard) }}</div>
            </template>
          </el-table-column>
          <el-table-column
              prop="packingRequirement"
              label="包装要求"
              align="center"
              width="180">
            <template slot-scope="scope">
              <div v-if="scope.$index == 1">
                <el-form-item>
                  <el-input v-model="formInline[index].packingRequirement" size="small" placeholder="点击输入包装要求"/>
                </el-form-item>
              </div>
              <div v-else>{{ (scope.row.packingRequirement) }}</div>
            </template>
          </el-table-column>
        </el-table>

        <div style="padding-top: 20px"></div>
      </template>
    </el-form>
    <!--    <send-sample-register-edit-modal></send-sample-register-edit-modal>-->
  </div>
</template>

<script>
import server from "@/util/request";
import sendSampleRegisterEditModal from "@/views/SendSampleRegisterEditModal";

export default {
  name: "BuyingOrder",
  components: {
    sendSampleRegisterEditModal
  },
  data() {
    return {
      tableData: undefined,
      valurArr: [],
      options: undefined,
      url: {
        queryMB001Url: '/buying-order/query/mb001-list',
        queryRecordUrl: '/buying-order/query/record-by-mb001',
        addUrl: '/buying-order/add',
      },
      formInline: [],
      fullscreenLoading: false
    }
  },
  created() {
    this.getListMB001()
  },
  methods: {
    getListMB001() {
      server({
        url: this.url.queryMB001Url,
        method: 'get',
      }).then(res => {
        this.options = res.data.data
        this.options.forEach((item, index) => {
          this.options[index] = {
            value: item,
            text: item
          }
        })
      })
    },
    getRecord() {
      if (this.valurArr.length === 0) {
        return
      }
      server({
        url: this.url.queryRecordUrl,
        method: "post",
        data: this.valurArr
      }).then(res => {
        this.tableData = res.data.data
        this.tableData.forEach((item, index) => {
          this.tableData[index].push({})
        })
        let length = this.tableData.length
        this.formInline = []
        for (let i = 0; i < length; i++) {
          this.formInline.push({})
          this.formInline[i].productNo = this.tableData[i][0].productNo
        }
      });
    },
    insertRecode() {
      this.fullscreenLoading = true;
      server({
        url: this.url.addUrl,
        method: 'post',
        data: this.formInline
      }).then(res => {
        if (res.data.success) {
          this.$notify({
            title: '成功',
            type: 'success'
          });
        }
      }).catch(err => {
        this.$notify.error({
          title: err,
        });
        this.fullscreenLoading = false
      }).finally(() => {
        this.fullscreenLoading = false
      })
    },
    submit() {
      this.$confirm('此操作, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.insertRecode()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });

    }
  },

}
</script>

<style scoped>
/deep/ .el-table__body-wrapper {
  background-color: #F7F6FF;
}

/deep/ .el-table__body-wrapper::-webkit-scrollbar {
  width: 10px !important;
  height: 10px !important;
}
</style>
